﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors.Repository;
using DevTeam;

using System;
using System.Drawing;

namespace ConfExpert.Forms.Siparisler
{
    public partial class AtelyeKapasitesi : XForm
    {
        public AtelyeKapasitesi()
        {
            InitializeComponent();
        }

        private void AtelyeKapasitesi_Load(object sender, EventArgs e)
        {
            gridView1.Init("GetUretimAtelyeleri");
            gridView1.AddDetailGrid(gridView2, "AtelyeId");
            gridView2.MakeColumnInvisible("EkIsId", "AtelyeId");
            gridView2.MakeReadOnly("EkIs");
            gridView1.AddColumn("Toplam Ek Is", typeof(int), "SUM(Child({FK}).EkIs)");
            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            gridView2.Columns["Gun"].ColumnEdit = new RepositoryItemDateEdit();
            ((RepositoryItemDateEdit)gridView2.Columns["Gun"].ColumnEdit).DisplayFormat.FormatString = "D";
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gridView2.RowCellStyle += gridView2_RowCellStyle;
        }

        void gridView2_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                string gun = gridView2.GetRowCellDisplayText(e.RowHandle, "Gun").ToStr();
                if (gun.EndsWith("Cumartesi") || gun.EndsWith("Pazar"))
                {
                    e.Appearance.BackColor = Color.LightPink;
                }
            }
        }


        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            gridView2.EndEditing();
            string str = gridView2.SerializeChanges();
            string strAtelye = gridView1.SerializeChanges();
            ExecuteNonQuery("InsKapasite", str,strAtelye);
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
          //  gridView2.Init("GetEkKapasiteler",gridView1.GetFocusedRowCellValue("AtelyeId"));
            gridView2.BestFitColumns();
        }
    }
}
